/**
 * @title
 * @description
 * @author 张玉华
 * @date 2020-11-17 10:26
 */
import {
  Connection,
  EntitySubscriberInterface,
  EventSubscriber,
  InsertEvent,
} from 'typeorm';
import { Order } from '../../entity/Order';

@EventSubscriber()
export class OrderSubscriber implements EntitySubscriberInterface<Order> {
  constructor(connection: Connection) {
    connection.subscribers.push(this);
  }

  listenTo() {
    return Order;
  }

  beforeInsert(event: InsertEvent<Order>) {
    console.log(`BEFORE order INSERTED: `, event.entity);
  }
}
